import 'package:ecy_app_flutter/routes/blind_box/exchange_market/models/blind_box_page.dart';
import 'package:flutter/material.dart';

class ImageSwitcher extends StatefulWidget {
  final List<BlindBoxDetailMore> images;
  const ImageSwitcher({super.key, required this.images});
  @override
  _ImageSwitcherState createState() => _ImageSwitcherState();
}

class _ImageSwitcherState extends State<ImageSwitcher> {
  final PageController _controller = PageController();
  int _currentPage = 0;

  List<String> images = [
    'https://picsum.photos/400/600?image=10',
    'https://picsum.photos/400/600?image=20',
    'https://picsum.photos/400/600?image=30',
    'https://picsum.photos/400/600?image=40',
    'https://picsum.photos/400/600?image=50',
  ];
  


  void _goPrevious() {
    if (_currentPage > 0) {
      _currentPage--;
      _controller.animateToPage(_currentPage, duration: Duration(milliseconds: 300), curve: Curves.ease);
    }
  }

  void _goNext() {
    if (_currentPage < images.length - 1) {
      _currentPage++;
      _controller.animateToPage(_currentPage, duration: Duration(milliseconds: 300), curve: Curves.ease);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        // 左侧按钮
        IconButton(
          icon: Icon(Icons.arrow_left, size: 30),
          onPressed: _goPrevious,
        ),
        // 图片区域
        Container(
          width: 250, // 设置固定宽度
          height: 300, // 设置固定高度
          child: PageView.builder(
            physics: NeverScrollableScrollPhysics(),
            controller: _controller,
            itemCount: images.length,
            onPageChanged: (index) {
              setState(() {
                _currentPage = index;
              });
            },
            itemBuilder: (context, index) {
              return Container(
                margin: EdgeInsets.symmetric(horizontal: 10),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  image: DecorationImage(
                    image: NetworkImage(images[index]),
                    fit: BoxFit.cover,
                  ),
                ),
              );
            },
          ),
        ),
        // 右侧按钮
        IconButton(
          icon: Icon(Icons.arrow_right, size: 30),
          onPressed: _goNext,
        ),
      ],
    );
  }
}
